<template>
  <div class="app-container">
    <el-form ref="submitParams" :model="submitParams" :rules="rules" label-width="160px">
      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item label="直接参与机构号：" prop="directOrg">
            <el-input v-model="submitParams.directOrg" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item label="直接参与机构名称：" prop="directOrgName">
            <el-input v-model="submitParams.directOrgName" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item label="证书绑定状态：" prop="certBindstat">
            <el-input v-model="submitParams.certBindstat" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item label="证书有效期起始日期：" prop="certDateBegin">
            <el-date-picker
              v-model="submitParams.certDateBegin"
              type="date"
              value-format="yyyyMMdd"
              placeholder=""
              disabled
              style="width: 100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item label="证书有效期结束日期：" prop="certDateEnd">
            <el-date-picker
              v-model="submitParams.certDateEnd"
              type="date"
              value-format="yyyyMMdd"
              placeholder=""
              disabled
              style="width: 100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item label="证书绑定时间：" prop="certBindTime">
            <el-date-picker
              v-model="submitParams.certBindTime"
              type="datetime"
              value-format="yyyyMMddHHmmss"
              placeholder=""
              disabled
              style="width: 100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item label="变更类型：" prop="changeType">
            <el-input v-model="submitParams.changeType" disabled />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item label="数字证书：" prop="digitalcertificate">
            <el-input v-model="submitParams.digitalcertificate" disabled />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item label="备注：" prop="remarks">
            <el-input v-model="submitParams.remarks" type="textarea" maxlength="256" show-word-limit/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :offset="5" :span="12">
          <el-form-item>
            <el-button type="primary" @click="submitForm" :loading="isLoading">提 交</el-button>
            <el-button @click="refresh">重 置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { queryUrl, submit } from "@/api/cnaps/ccms/903/digital_certificate_manage";
import { listPageMixin } from "@/libs/listPageMixin";
export default {
  name: "DigitalCertificateManage",
  mixins: [listPageMixin],
  components: {},
  data() {
    return {
      isLoading: false,
      // 录入参数
      submitParams: {
        directOrg: "",
        directOrgName: "",
        certBindstat: "",
        certDateBegin: "",
        certDateEnd: "",
        certBindTime: "",
        changeType: "",
        digitalcertificate: "",
        remarks: "",
      },

      rules: {
        directOrg: [{ required: true, message: "请输入系统编号", trigger: "blur" }],
        changeType: [{ required: true, message: "请输入接收方", trigger: "blur" }],
      },
    };
  },
  mounted() {},
  created() {
    queryUrl().then((res) => {
      this.submitParams = res.result.data;
      console.log(res.result.data.certBindstat);
      if (res.result.data.certBindstat == "0-未绑定") {
        this.submitParams.changeType = "CC00-新增";
      } else if (res.result.data.certBindstat == "1-已绑定") {
        this.submitParams.changeType = "CC02-撤销";
      }
    });
  },
  methods: {
    /** 提交按钮 */
    submitForm() {
      this.$refs["submitParams"].validate((valid) => {
        if (valid) {
          this.loading = true;
          submit(this.submitParams)
            .then(() => {
              this.msgSuccess("成功");
              this.refresh();
              this.loading = false;
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
    //点击重置按钮
    refresh() {
      this.submitParams.remarks = "";
    },
  },
};
</script>
